﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for PaymentDAL
/// </summary>
public class PaymentDAL
{
    string str = ConfigurationManager.ConnectionStrings["SmartAccessories"].ToString();	
    public PaymentDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable LoadPayment()
    {
        SqlConnection cnn = new SqlConnection(str);
        cnn.Open();
        SqlDataAdapter da = new SqlDataAdapter("sp_LoadPayment", cnn);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;
        DataSet ds = new DataSet();
        DataTable dt;
        try
        {
            da.Fill(ds);
            dt = ds.Tables[0];
            return dt;

        }
        catch
        {
            throw;
        }
        finally
        {
            ds.Dispose();
            da.Dispose();
            cnn.Close();
            cnn.Dispose();
        }
    }
    public int insertPayment(Payment p)
    {
        SqlConnection cnn = new SqlConnection(str);
        cnn.Open();
        SqlCommand cmd = new SqlCommand("sp_INSERT_PAYMENT", cnn);
        cmd.CommandType = CommandType.StoredProcedure;
        try
        {
            cmd.Parameters.AddWithValue("@PaymentID",p.PaymentID);
            cmd.Parameters.AddWithValue("@ShoppingID", p.ShoppingID);
            cmd.Parameters.AddWithValue("@DatePayment", p.Datepayment);
            cmd.Parameters.AddWithValue("@PaymentType", p.PaymentType);
            cmd.Parameters.AddWithValue("@ServiceCharges",p.ServiceCharges);

            return cmd.ExecuteNonQuery();
        }
        catch
        {
            throw;
        }
        finally
        {
            cmd.Dispose();
            cnn.Close();
            cnn.Dispose();
        }
    }
}